<%--
  Created by IntelliJ IDEA.
  User: hasee
  Date: 2017/10/24
  Time: 17:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>分页管理页面</title>
</head>
<body>
<h1 align="center">商品列表</h1>
<form align="center" action="${pageContext.request.contextPath}/searchByKeywordServlet">
    <table align="center" width="50%">
        <tr>
            <td><input type="text" name="keyword" value=""><input type="submit" value="查询"></td>
        </tr>
    </table>
</form>
<div align="center"><a href="${pageContext.request.contextPath}/product/addproduct.jsp" >添加</a></div>
<form action="" align="center">
    <table border="1" align="center" width="50%">
        <tr>
            <td width="5%">序号</td>
            <td width="10%">商品名称</td>
            <td width="5%">价格</td>
            <td width="2%">操作</td>
        </tr>
        <c:forEach var="product" items="${productlist}" varStatus="status">
            <c:choose>
                <c:when test="${(status.count+(param.page-1)*20)%2==0}">
                    <tr style="background-color: darkgray">
                        <td>${status.count+(param.page-1)*20}</td>
                        <td>${product.pname}</td>
                        <td>${product.shopPrice}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/editUIServlet?pid=${product.pid}">修改</a>&nbsp
                            <a href="javascript:if(confirm('确定删除该商品?'))location='${pageContext.request.contextPath}/removeProductServlet?pid=${product.pid}'">删除</a>
                        </td>
                    </tr>
                </c:when>
                <c:otherwise>
                    <tr style="background-color: mediumaquamarine">
                        <td>${status.count+(param.page-1)*20}</td>
                        <td>${product.pname}</td>
                        <td>${product.shopPrice}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/editUIServlet?pid=${product.pid}">修改</a>&nbsp
                            <a href="javascript:if(confirm('确定删除该商品?'))location='${pageContext.request.contextPath}/removeProductServlet?pid=${product.pid}'">删除</a>
                        </td>
                    </tr>
                </c:otherwise>
            </c:choose>
        </c:forEach>
    </table>
    <p>
        <c:if test="${param.page>1}"><a href="${pageContext.request.contextPath}/productListByPageServlet?page=${param.page-1}">上一页</a></c:if>
        <c:if test="${param.page<size}"><a href="${pageContext.request.contextPath}/productListByPageServlet?page=${param.page+1}">下一页</a></c:if>
    </p>
    <p>
        <c:if test="${param.page-3>0}"><a href="${pageContext.request.contextPath}/productListByPageServlet?page=${param.page-3}">${param.page-3}</a></c:if>
        <c:if test="${param.page-2>0}"><a href="${pageContext.request.contextPath}/productListByPageServlet?page=${param.page-2}">${param.page-2}</a></c:if>
        <c:if test="${param.page-1>0}"><a href="${pageContext.request.contextPath}/productListByPageServlet?page=${param.page-1}">${param.page-1}</a></c:if>
        <a href="${pageContext.request.contextPath}/productListByPageServlet?page=${param.page}">${param.page}</a>
        <c:if test="${param.page+1<=size}"><a href="${pageContext.request.contextPath}/productListByPageServlet?page=${param.page+1}">${param.page+1}</a></c:if>
        <c:if test="${param.page+2<=size}"><a href="${pageContext.request.contextPath}/productListByPageServlet?page=${param.page+2}">${param.page+2}</a></c:if>
        <c:if test="${param.page+3<=size}"><a href="${pageContext.request.contextPath}/productListByPageServlet?page=${param.page+3}">${param.page+3}</a></c:if>
    </p>
    <p>第${param.page}页&nbsp共${size}页</p>
</form>
</body>
</html>
